﻿using HuiLian.Common.Input;
using HuiLian.Common.Output;
using HuiLian.Model.Platform;
using HuiLian.Service.HdlScada.AlarmRealTime;
using HuiLian.Service.HdlScada.HdlScadaAlarmHistory;
using HuiLian.Service.HdlScada.HdlScadaAlarmHistory.Input;
using HuiLian.Web.Controllers.Platform;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace HuiLian.Web.Controllers.HdlScada
{
    /// <summary>
    /// 历史报警记录
    /// </summary>
    public class HdlScadaAlarmHistoryController : AreaController
    {
        private readonly IHdlScadaAlarmHistoryService _hdlScadaAlarmHistoryServices;

        public HdlScadaAlarmHistoryController(IHdlScadaAlarmHistoryService hdlScadaAlarmHistoryServices)
        {
            _hdlScadaAlarmHistoryServices = hdlScadaAlarmHistoryServices;
        }

        /// <summary>
        /// 查询单条模型执行记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IResponseOutput> Get(long id)
        {
            return await _hdlScadaAlarmHistoryServices.GetAsync(id);
        }

        /// <summary>
        /// 查询分页实时报警记录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IResponseOutput> GetPage(PageInput<HdlScadaAlarmHistoryEntity> model)
        {
            return await _hdlScadaAlarmHistoryServices.PageAsync(model);
        }

        [HttpGet]
        public async Task<IResponseOutput> Import()
        {
            //分页导出txt文件，再读取txt文件，导入数据库
            string path = @"C:\Users\admin\Desktop\报警\历史报警.txt";
            string text = System.IO.File.ReadAllText(path);
            Root hdlScadaAlarmHistoryListInput = Newtonsoft.Json.JsonConvert.DeserializeObject<Root>(text);

            return ResponseOutput.Ok(true);
        }
    }
}
